package com.backtracking;

import java.util.*;

public class Solution14 {
    List<List<Integer>> res = new ArrayList<>();
    LinkedList<Integer> tmp = new LinkedList<>();

    public List<List<Integer>> findSubsequences(int[] nums) {
        backTracking(nums,0);
        return res;
    }


    public void backTracking(int[] nums, int index) {
        if (index >= nums.length) {
            return;
        }

        HashMap<Integer,Integer> map = new HashMap<>();
        for (int i = index; i < nums.length; i++) {
            if (!tmp.isEmpty() && nums[i] < tmp.getLast()) continue;
            if (map.getOrDefault(nums[i],0)>=1) continue;
            map.put(nums[i], map.getOrDefault(nums[i],0)+1);
            tmp.add(nums[i]);
            if (tmp.size() >= 2)
                res.add(new ArrayList<>(tmp));
            backTracking(nums,i+1);
            tmp.removeLast();
        }
    }
}
